import {persistReducer, persistStore} from 'redux-persist'
import {adminReducer, appReducer, layoutReducer, loadNewReducer, store} from "@kordar-lib/reducers";
import {combineReducers} from "redux";
import datasetReducer from "./store/dataset"
import bucketReducer from "./store/bucket"
import storage from "redux-persist/lib/storage";

const persistConfigUser = { key: 'user', storage: storage, whitelist: ['token', 'info']}
let persistedReducerUser = persistReducer(persistConfigUser, adminReducer)

// 注入app
const persistConfigApp = { key: 'app', storage: storage, whitelist: ['sidebarCollapsed', 'locale', 'localeOptions', 'historyLocation', 'theme']}
let persistedReducerApp = persistReducer(persistConfigApp, appReducer)

// 注入layout
const persistConfigLayout = { key: 'layout', storage: storage, whitelist: ['choices', 'tabs', 'choiceId']}
let persistedReducerLayout = persistReducer(persistConfigLayout, layoutReducer)

// 注入dataset
const datasetConfig = { key: 'dataset', storage: storage, whitelist: ['datasetImageTabIndex']}
let datasetConfigReducer = persistReducer(datasetConfig, datasetReducer)

// 注入bucket
const bucketConfig = { key: 'bucket', storage: storage, whitelist: []}
let bucketConfigReducer = persistReducer(bucketConfig, bucketReducer)

loadNewReducer(combineReducers({
    user: persistedReducerUser,
    app: persistedReducerApp,
    layout: persistedReducerLayout,
    dataset: datasetConfigReducer,
    bucket: bucketConfigReducer,
}));

let persistor = persistStore(store)

export {
    persistor,
    store,
}